package com.wm.ad_navi_new.skin.util

import com.wm.ad_navi_new.skin.AbstractSkinAttr
import com.wm.ad_navi_new.skin.attr.subclass.BackgroundAttr

object AttrUtil {

    private val mSupportAttr = HashMap<String, AbstractSkinAttr>()

    init {
        /**
         * 如果view在list中尽量不要使用这种方式，因为listView存在view复用情况，会导致view属性不会刷新
         */
        mSupportAttr["background"] = BackgroundAttr()
//        mSupportAttr["textColor"] = TextColorAttr()
//        mSupportAttr["textSize"] = TextSizeAttr()
//        mSupportAttr["src"] = ImageViewSrcAttr()
//        mSupportAttr["drawableTop"] = CompoundDrawableAttr()
//        mSupportAttr["drawableLeft"] = CompoundDrawableAttr()
//        mSupportAttr["drawableRight"] = CompoundDrawableAttr()
//        mSupportAttr["drawableBottom"] = CompoundDrawableAttr()
//        mSupportAttr["layout_marginTop"] = ViewAttr()
//        mSupportAttr["layout_width"] = ViewAttr()
//        mSupportAttr["layout_height"] = ViewAttr()
//        mSupportAttr["textColorHint"] = EditTextColorHintAttr()
//        mSupportAttr["progressDrawable"] = ProgressDrawableAttr()
//        mSupportAttr["cardBackgroundColor"] = CardBackgroundColorAttr()
    }

    fun isSupportedAttr(attrName: String): Boolean {
        return mSupportAttr.containsKey(attrName)
    }

    /**
     * attrName--当前修改的属性，返回null，则是不支持此属性
     *
     */
    operator fun get(attrName: String?, attrValueRefId: Int, attrValueRefName: String, typeName: String?): AbstractSkinAttr? {
        val mSkinAttr: AbstractSkinAttr = (mSupportAttr[attrName]?.clone() ?: return null) as AbstractSkinAttr
        mSkinAttr.attrName = attrName
        mSkinAttr.attrValueRefId = attrValueRefId
        mSkinAttr.attrValueRefName = attrValueRefName
        mSkinAttr.attrValueTypeName = typeName
        return mSkinAttr
    }

}